package com.wc.alorithm_blue_bridge._动态规划.背包问题.Q1176;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.StreamTokenizer;

/**
 * @Author congege
 * @Description 小明的背包3
 * https://www.lanqiao.cn/problems/1176/learning/?page=2&first_category_id=1&sort=students_count&second_category_id=8
 * @Date Created in 2023/11/7-10:01
 */
public class Main {
    public static void main(String[] args) {
        Input sc = new Input();
        int n = sc.nextInt();
        int m = sc.nextInt();
        int[][] dp = new int[n][m + 1];
        Good[] goods = new Good[n];
        for (int i = 0; i < n; i++) {
            Good good = new Good();
            goods[i] = good;
            good.w = sc.nextInt();
            good.v = sc.nextInt();
            good.s = sc.nextInt();
        }
        for (int j = goods[0].w; j <= m; j++) {
            int num = Math.min(j / goods[0].w, goods[0].s);
            dp[0][j] = num * goods[0].v;
        }

        for (int i = 1; i < n; i++) {
            for (int j = 0; j <= m; j++) {
                if (j >= goods[i].w) {
                    int num = Math.min(j / goods[i].w, goods[i].s);
                    int maxV = 0;
                    for (int k = 0; k <= num; k++) {
                        maxV = Math.max(maxV, dp[i - 1][j - k * goods[i].w] + k * goods[i].v);
                    }
                    dp[i][j] = Math.max(maxV, dp[i - 1][j]);
                }else {
                    dp[i][j] = dp[i - 1][j];
                }
            }
        }

        System.out.println(dp[n - 1][m]);
    }

    static class Good {
        int w;
        int v;
        int s;
    }

    static class Input {
        StreamTokenizer in = new StreamTokenizer(new BufferedReader(new InputStreamReader(System.in)));

        public int nextInt() {
            try {
                in.nextToken();
            } catch (IOException e) {
                e.printStackTrace();
            }
            return (int) in.nval;
        }
    }
}
